package com.itboye.lottery.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.bylibrary.widget.glide.GlideUtil;
import com.itboye.lottery.R;
import com.itboye.lottery.bean.IndexDataBean;

import java.util.List;

/**
 * Created by wu on 2018/1/9.
 */

public class HomeLotteryClassificationAdapter extends RecyclerView.Adapter<HomeLotteryClassificationAdapter.ViewHolder> {

    private Context context;
    private List<IndexDataBean.Caizhong> list;
    private int type;

    public HomeLotteryClassificationAdapter(List<IndexDataBean.Caizhong> list) {
        this.list = list;
    }

    public OnItemClickListener itemClickListener;

    public void setOnItemClickListener(HomeLotteryClassificationAdapter.OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    public void setType(int type) {
        this.type = type;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    @Override
    public HomeLotteryClassificationAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View v = LayoutInflater.from(context).inflate(R.layout.item_lottery_classfication, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(HomeLotteryClassificationAdapter.ViewHolder holder, int position) {
        GlideUtil.display(context, (list.get(position).getLogo()),holder.img, R.mipmap.lottery_circle, true);
        holder.name.setText(list.get(position).getAlias_name());
        int res=getStatusValue(list.get(position).getStatus());
        if (res!=0) {
            holder.item_classfy_status.setImageResource(getStatusValue(list.get(position).getStatus()));
            holder.item_classfy_status.setVisibility(View.VISIBLE);
            holder.itemView.setTag(getStatusStringValue(list.get(position).getStatus()));
        }else{
            holder.item_classfy_status.setVisibility(View.GONE);
        }
    }

    private int getStatusValue(int status) {
        int statusValue = 0;//默认0,1待开发，2今日开奖
        switch (status) {
            case 0:
                break;
            case 1:
                statusValue = R.mipmap.ic_wait_dev2;
                break;
            case 2:
                statusValue = R.mipmap.ic_stopsale_ing2;
                break;
            case 3:
                statusValue = R.mipmap.ic_prize2;
                break;
        }
        return statusValue;
    }

    private String getStatusStringValue(int status) {
        String statusValue = "";//默认0,1待开发，2停售中,3今日开奖
        switch (status) {
            case 0:
                break;
            case 1:
                statusValue = "待开发";
                break;
            case 2:
                statusValue = "停售中";
                break;
        }
        return statusValue;
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        public ImageView img,item_classfy_status;
        public TextView name ;
        View itemView;
        public ViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            img = itemView.findViewById(R.id.img);
            name = itemView.findViewById(R.id.name);
            item_classfy_status = itemView.findViewById(R.id.item_classfy_status);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (itemClickListener != null) {
                itemClickListener.onItemClick(v, getAdapterPosition());
            }
        }
    }
}
